﻿using System;
using System.Collections.Generic;
using System.Web;
using BaseSet.Framework.Config;
using BaseSet.Entity.Common.Text;
using BaseSet.Entity;
using BaseSet.Entity.Common;
using System.Data;

namespace WebSite
{
    public class CommonClass
    {
        /// <summary>
        /// 返回列表页通过指定的url，并保持当前的页面，查询条件需要在列表页中处理
        /// </summary>
        /// <param name="targetUrl">返回目标的URL</param>
        public static void ReturnListPage(string targetUrl)
        {
            string pnPrifix = Keys.QRYSTR_PAGEINDEX;
            string pn = "";
            if (System.Web.HttpContext.Current.Request[pnPrifix] != null && System.Web.HttpContext.Current.Request[pnPrifix].ToString() != "")
            {
                pn = System.Web.HttpContext.Current.Request[pnPrifix].ToString();
            }

            string pageInfo = "";

            if (!string.IsNullOrEmpty(pn))
            {
                pageInfo += "?" + pnPrifix + "=" + pn;
                targetUrl = targetUrl + pageInfo;
            }

            System.Web.HttpContext.Current.Response.Redirect(targetUrl);

        }

        /// <summary>
        /// 跳转到目标地址，并将当前页码传递过去，与ReturnListPage一起使用
        /// </summary>
        /// <param name="pageNumber"></param>
        /// <param name="url"></param>
        public static void RedirectTargetUrl(int pageNumber,string url)
        {
            //传递页码信息
            string pn = pageNumber.ToString();
            string pnPrifix = Keys.QRYSTR_PAGEINDEX;

            string pageInfo = "";
            if (!string.IsNullOrEmpty(pn))
            {
                pageInfo += "&" + pnPrifix + "=" + pn;
            }

            //string url = "SeoEdit.aspx?id=" + id + "&groupname=" + groupname + "&name=" + name;

            if (!string.IsNullOrEmpty(pageInfo))
            {
                url = url + pageInfo;
            }

            System.Web.HttpContext.Current.Response.Redirect(url);

        }


        /// <summary>
        /// 当前页面的url
        /// </summary>
        public string CurrentPageUrl
        {
            get
            {
                string relUrl = "";
                string url = System.Web.HttpContext.Current.Request.Url.AbsoluteUri.Replace(UserBase.GetServerPath(), "").Trim();

                if (url.IndexOf('?') > 0)
                {
                    relUrl = url.Substring(0, url.IndexOf('?'));
                }
                else
                {
                    relUrl = url;
                }

                return relUrl;
            }
        }

        /// <summary>
        /// 获取url传递过来的ID，主要用于url重写时确定目标对象
        /// </summary>
        public string ObjectID
        {
            get
            {
                string id = System.Web.HttpContext.Current.Request["ID"];

                return id;
            }
        }
    }
}